/**
 * 品牌
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author duanzucai
 * @since 2018/11/10
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate','jquery'], function (exports) {
    var $ = layui.$;
    var table = layui.table;
    var laypage = layui.laypage;
    var laydate = layui.laydate;
    var form = layui.form;
    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-140'
    });

    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-brand-filter", {
            "nameOrBrandId": "" // "name": "value"
            ,"type": ""
            ,"status": ''
            ,"timeRange": ""
        });
        return false;
    });

    laydate.render({elem: "#timeRange", range: true, format: 'yyyy/MM/dd'});
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.brandId);
    });

    // 修改排序
    table.on("edit(zmn-table)", function (obj) {
        zmnPage.laySort(obj, "/brand/updateSort.action", obj.data.brandId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event != "start" && obj.event != "stop") {
            return;
        }
        if (ids.length === 0) {
            return layer.alert("请选择至少一个品牌！");
        }
        zmnPage.layStartStop(obj, "/brand/updateStatus.action", ids.join(","));
    });

    form.on("switch(chk_one_status)", function (obj) {
        let  url = "/brand/updateStatus.action";
        let brandId = obj.elem.getAttribute("key");
        let status = obj.elem.checked ? 2 : 1;
        switch (status) {
            case 1:
                zmnPage.ajaxSimple(url, {ids: brandId, status: 1}, 1000);
                break;
            case 2:
                zmnPage.ajaxSimple(url, {ids: brandId, status: 2}, 1000);
                break;
        }
        setTimeout(function () {
            location.reload(true);
        }, 3000);
    });

    //对外暴露的接口
    exports('art_brand_list', {});
});

//显示描述
function show_tips(flag, tips, obj){
    //小tips
    //如果没有权限则提示
    if (!flag) {
        layer.tips(tips,obj,{
            tips:[1,'#3595CC'],
            time:3000
        })
    }
}